/*
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package main;

import server.IntelServerType;
import tools.StringTools;

/**
 * A class containing the basic bot settings
 * 
 * 
 */
public final class BotSettings {
   private String releaseVersion = "";
   private int botVersion = 11;
   private int tickLength = 60;
   private String dbHost = "";
   private String dbName = "";
   private String dbUsername = "";
   private String dbPassword = "";
   private String ircServer = "";
   private int ircPort = 6667;
   private int ircDelay = 1000;
   private String botNick = "";
   private String botPassword = "";
   private String mainChannel = "";
   private String mainChannelPw = "";
   private String adminChannel = "";
   private String adminChannelPw = "";
   private Long ageStart = 0L;
   private String kdLoc = "";
   private int intelPort = 0;
   private IntelServerType intelServerType = null;
   private int rpcServicePort = 0;
   private boolean usersMayRegister = false;
   private boolean limitAdminCommands = false;
   private boolean passwordAuth = false;
   private String commandPrefix = "!";

   private boolean listenForIntel = false;
   private boolean runRPCService = false;
   private String rpcPassword = "";

   private String smsSMTP = "";
   private String smsUser = "";
   private String smsPassword = "";
   private int smsPort = 0;
   private String googleAPIKey = "";

   BotSettings() {
   }

   public String getAdminChannel() {
	  return adminChannel;
   }

   public String getAdminChannelPw() {
	  return adminChannelPw;
   }

   public Long getAgeStart() {
	  return ageStart;
   }

   public String getBotNick() {
	  return botNick;
   }

   public String getBotPassword() {
	  return botPassword;
   }

   public int getBotVersion() {
	  return botVersion;
   }

   public String getCommandPrefix() {
	  return commandPrefix;
   }

   public String getDbHost() {
	  return dbHost;
   }

   public String getDbName() {
	  return dbName;
   }

   public String getDbPassword() {
	  return dbPassword;
   }

   public String getDbUsername() {
	  return dbUsername;
   }

   public String getGoogleAPIKey() {
	  return googleAPIKey;
   }

   public int getIntelPort() {
	  return intelPort;
   }

   public IntelServerType getIntelServerType() {
	  return intelServerType;
   }

   public String getIrcServer() {
	  return ircServer;
   }
   
   public int getIrcPort() {
	  return ircPort;
   }
   
   public int getIrcDelay() {
	  return Math.max(ircDelay, 0);
   }

   public String getKdLoc() {
	  return kdLoc;
   }

   public String getMainChannel() {
	  return mainChannel;
   }

   public String getMainChannelPw() {
	  return mainChannelPw;
   }

   public String getReleaseVersion() {
	  return releaseVersion;
   }

   public String getRPCPassword() {
	  return rpcPassword;
   }

   public int getRpcServicePort() {
	  return rpcServicePort;
   }

   public String getSmsPassword() {
	  return smsPassword;
   }

   public int getSmsPort() {
	  return smsPort;
   }

   public String getSmsSMTP() {
	  return smsSMTP;
   }

   public String getSmsUser() {
	  return smsUser;
   }

   public int getTickLength() {
	  return tickLength;
   }

   /**
    * Checks whether the necessary settings to run the bot exist
    * 
    * @return
    */
   public boolean hasRequiredFields() {
	  return !StringTools.isNullOrEmpty(dbHost) && !StringTools.isNullOrEmpty(dbName) && !StringTools.isNullOrEmpty(dbUsername)
			&& !StringTools.isNullOrEmpty(dbPassword) && !StringTools.isNullOrEmpty(ircServer)
			&& !StringTools.isNullOrEmpty(botNick) && !StringTools.isNullOrEmpty(botPassword)
			&& !StringTools.isNullOrEmpty(mainChannel) && ageStart != null && !StringTools.isNullOrEmpty(kdLoc);
   }

   public boolean limitAdminCommands() {
	  return limitAdminCommands;
   }

   public boolean listenForIntel() {
	  return listenForIntel && intelPort != 0;
   }

   public void listenForIntel(final boolean listenForIntel) {
	  this.listenForIntel = listenForIntel;
   }

   public boolean requirePasswordAuth() {
	  return false;
   }

   public boolean runRPCService() {
	  return runRPCService && rpcServicePort != 0;
   }

   public void runRPCService(final boolean runRPCService) {
	  this.runRPCService = runRPCService;
   }

   public void setAdminChannel(final String adminChannel) {
	  if (adminChannel.split(" ").length > 1) {
		 String[] split = adminChannel.split(" ");
		 this.adminChannel = split[0];
		 adminChannelPw = split[1];
	  } else {
		 this.adminChannel = adminChannel;
	  }
   }

   public void setAgeStart(final Long ageStart) {
	  this.ageStart = ageStart;
   }

   public void setBotNick(final String botNick) {
	  this.botNick = botNick;
   }

   public void setBotPassword(final String botPassword) {
	  this.botPassword = botPassword;
   }

   public void setBotVersion(final int botVersion) {
	  this.botVersion = botVersion;
   }

   public void setCommandPrefix(final String commandPrefix) {
	  this.commandPrefix = commandPrefix;
   }

   public void setDbHost(final String dbHost) {
	  this.dbHost = dbHost;
   }

   public void setDbName(final String dbName) {
	  this.dbName = dbName;
   }

   public void setDbPassword(final String dbPassword) {
	  this.dbPassword = dbPassword;
   }

   public void setDbUsername(final String dbUsername) {
	  this.dbUsername = dbUsername;
   }

   public void setGoogleAPIKey(final String googleAPIKey) {
	  this.googleAPIKey = googleAPIKey;
   }

   public void setIntelPort(final int intelPort) {
	  this.intelPort = intelPort;
   }

   public void setIntelServerType(final IntelServerType intelServerType) {
	  this.intelServerType = intelServerType;
   }

   public void setIrcServer(final String ircServer) {
	  this.ircServer = ircServer;
   }
   
   public void setIrcPort(final int ircPort) {
	  this.ircPort = ircPort;
   }
   
   public void setIrcDelay(final int ircDelay) {
	  this.ircDelay = ircDelay;
   }

   public void setKdLoc(final String kdLoc) {
	  this.kdLoc = kdLoc;
   }

   public void setLimitAdminCommands(final boolean limitAdminCommands) {
	  this.limitAdminCommands = limitAdminCommands;
   }

   public void setMainChannel(final String mainChannel) {
	  if (mainChannel.split(" ").length > 1) {
		 String[] split = mainChannel.split(" ");
		 this.mainChannel = split[0];
		 mainChannelPw = split[1];
	  } else {
		 this.mainChannel = mainChannel;
	  }
   }

   public void setPasswordAuth(final boolean passwordAuth) {
	  this.passwordAuth = passwordAuth;
   }

   public void setReleaseVersion(final String releaseVersion) {
	  this.releaseVersion = releaseVersion;
   }

   public void setRPCServicePassword(final String rpcPassword) {
	  this.rpcPassword = rpcPassword;
   }

   public void setRPCServicePort(final int rpcServicePort) {
	  this.rpcServicePort = rpcServicePort;
   }

   public void setSmsPassword(final String smsPassword) {
	  this.smsPassword = smsPassword;
   }

   public void setSmsPort(final int smsPort) {
	  this.smsPort = smsPort;
   }

   public void setSmsSMTP(final String smsSMTP) {
	  this.smsSMTP = smsSMTP;
   }

   public void setSmsUser(final String smsUser) {
	  this.smsUser = smsUser;
   }

   public void setTickLength(final int tickLength) {
	  this.tickLength = tickLength;
   }

   public void setUsersMayRegister(final boolean usersMayRegister) {
	  this.usersMayRegister = usersMayRegister;
   }

   public boolean useEmbeddedDB() {
	  return "embedded".equalsIgnoreCase(dbHost);
   }

   public boolean usersMayRegister() {
	  return usersMayRegister;
   }
}